//
//  PushTransitionAnimation.m
//  29-TransitionAnimation
//
//  Created by Snow on 16/8/23.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "PushTransitionAnimation.h"
#import "ViewController.h"
#import "SecondViewController.h"
@implementation PushTransitionAnimation

- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext
{
    return 0.5f;
}
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
   ViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
   SecondViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIView *containerView = [transitionContext containerView];
    [containerView addSubview:toVC.view];
    toVC.ToVCImageView.hidden = YES;
    //jie tu
   UIView *snapView = [fromVC.FromVC snapshotViewAfterScreenUpdates:NO];
    snapView.frame = fromVC.FromVC.frame;
    [containerView addSubview:snapView];
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
    [containerView layoutIfNeeded];
    snapView.frame = toVC.ToVCImageView.frame;
} completion:^(BOOL finished) {
    toVC.ToVCImageView.hidden = NO;
    [snapView removeFromSuperview];
    [transitionContext completeTransition:YES];
}];
}
@end
